<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <textarea name="" id="" cols="80" rows="10"></textarea>
    <button class="post">点击发布</button>
    <div class="list">
    </div>

    <script>
        //获取元素
        var btn = document.querySelector('button')
        var text = document.querySelector('textarea')
        var list = document.querySelector('.list')
        //注册事件
        btn.onclick = function(){
            if(text.value == ''){
                alert('请输入内容')
                return false;
            }else{
                var li = document.createElement('li');
                li.innerHTML = text.value;
                list.insertBefore(li,list.children[0])
            }
        }

    </script>
</body>
</html>